package hu.ikti.oamadmin.types.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.validator.NotEmpty;
import org.jboss.seam.annotations.Name;

@Entity
@Name("address")
@Table(name = "ADDRESS")
@SequenceGenerator(sequenceName = "ADDRESS_SEQ", name = "ADDR_SEQ", allocationSize = 1)
public class Address implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long id;
	private String country;
	private String city;
	private int zipCode;
	private String street;
	private int streetNumber;
	private String additionalInfo;

	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "ADDR_SEQ")
	public Long getId() {
		return id;
	}

	@Column(name = "COUNTRY", nullable = false)
	@NotEmpty(message = "not empty")
	public String getCountry() {
		return country;
	}

	@Column(name = "CITY", nullable = false)
	@NotEmpty(message = "not empty")
	public String getCity() {
		return city;
	}

	@Column(name = "ZIPCODE", nullable = false)
	public int getZipCode() {
		return zipCode;
	}

	@Column(name = "STREET", nullable = false)
	@NotEmpty(message = "not empty")
	public String getStreet() {
		return street;
	}

	@Column(name = "ADDITIONAL_INFO")
	public String getAdditionalInfo() {
		return additionalInfo;
	}

	@Column(name = "STREET_NUMBER", nullable = false)
	public int getStreetNumber() {
		return streetNumber;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public void setZipCode(int zipCode) {
		this.zipCode = zipCode;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public void setAdditionalInfo(String additionalInfo) {
		this.additionalInfo = additionalInfo;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setStreetNumber(int streetNumber) {
		this.streetNumber = streetNumber;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((additionalInfo == null) ? 0 : additionalInfo.hashCode());
		result = prime * result + ((city == null) ? 0 : city.hashCode());
		result = prime * result + ((country == null) ? 0 : country.hashCode());
		result = prime * result + ((street == null) ? 0 : street.hashCode());
		result = prime * result + streetNumber;
		result = prime * result + zipCode;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Address other = (Address) obj;
		if (additionalInfo == null) {
			if (other.additionalInfo != null)
				return false;
		} else if (!additionalInfo.equals(other.additionalInfo))
			return false;
		if (city == null) {
			if (other.city != null)
				return false;
		} else if (!city.equals(other.city))
			return false;
		if (country == null) {
			if (other.country != null)
				return false;
		} else if (!country.equals(other.country))
			return false;
		if (street == null) {
			if (other.street != null)
				return false;
		} else if (!street.equals(other.street))
			return false;
		if (streetNumber != other.streetNumber)
			return false;
		if (zipCode != other.zipCode)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Address [country=" + country + ", city=" + city + ", zipCode="
				+ zipCode + ", street=" + street + ", streetNumber="
				+ streetNumber + ", additionalInfo=" + additionalInfo + "]";
	}

}
